Pyramid.prototype = new Shape3D();  
Pyramid.prototype.constructor=Pyramid;
function Pyramid(position, points, colors){
	this.position = position;
	this.points = points;
	this.vertices = new Array();
	this.vertexSize = 3;
	
	this.colors = colors?colors:null;
	this.verticeColors = null;
	this.colorSize = 4;
	this.animations = new Array();
	
	this.initVertices = function(){
		if(this.points.length<4) throw "We need 4 points for defining a pyramid.";

		// first point is the head
		// construct faces
		this.vertices = new Array();
		var h1 = this.points[0];
		
		for(var i=1;i<this.points.length-1;i++){
			var v1=this.points[i];
			var v2=this.points[i+1];
			this.vertices.push(h1.x);this.vertices.push(h1.y);this.vertices.push(h1.z);
			this.vertices.push(v1.x);this.vertices.push(v1.y);this.vertices.push(v1.z);
			this.vertices.push(v2.x);this.vertices.push(v2.y);this.vertices.push(v2.z);
		}
		var v1=this.points[1];
		var v2=this.points[this.points.length-1];
		this.vertices.push(h1.x);this.vertices.push(h1.y);this.vertices.push(h1.z);
		this.vertices.push(v1.x);this.vertices.push(v1.y);this.vertices.push(v1.z);
		this.vertices.push(v2.x);this.vertices.push(v2.y);this.vertices.push(v2.z);
		
		// construct colors
		if(colors){
			if(this.colors.length!=3) throw "We need 3 color points for defining a pyramid color.";
			this.verticeColors = new Array();
			var c1=this.colors[0];
			var c2=this.colors[1];
			var c3=this.colors[2];
			for(var i=1;i<this.points.length;i++){
				this.verticeColors.push(c1.r);this.verticeColors.push(c1.g);this.verticeColors.push(c1.b);this.verticeColors.push(c1.a);
				this.verticeColors.push(c2.r);this.verticeColors.push(c2.g);this.verticeColors.push(c2.b);this.verticeColors.push(c2.a);
				this.verticeColors.push(c3.r);this.verticeColors.push(c3.g);this.verticeColors.push(c3.b);this.verticeColors.push(c3.a);
			}
		}
	}
}